package com.example.service;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import com.example.common.enums.RoleEnum;
import com.example.entity.Account;
import com.example.entity.Interview;
import com.example.exception.CustomException;
import com.example.mapper.InterviewMapper;
import com.example.utils.TokenUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 面试信息业务层方法
 */
@Service
public class InterviewService {

    @Resource
    private InterviewMapper interviewMapper;

    public void add(Interview interview) {
        interview.setStatus("已预约");
        interviewMapper.insert(interview);
    }

    public void updateById(Interview interview) {
        interviewMapper.updateById(interview);
    }

    public void deleteById(Integer id) {
        interviewMapper.deleteById(id);
    }

    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids) {
            interviewMapper.deleteById(id);
        }
    }

    public Interview selectById(Integer id) {
        return interviewMapper.selectById(id);
    }

    public List<Interview> selectAll(Interview interview) {
        return interviewMapper.selectAll(interview);
    }

    public PageInfo<Interview> selectPage(Interview interview, Integer pageNum, Integer pageSize) {
        Account currentUser = TokenUtils.getCurrentUser();
        if (RoleEnum.USER.name().equals(currentUser.getRole())) {
            interview.setUserId(currentUser.getId());
        }
        if (RoleEnum.EMPLOY.name().equals(currentUser.getRole())) {
            interview.setEmployId(currentUser.getId());
        }
        PageHelper.startPage(pageNum, pageSize);
        List<Interview> list = interviewMapper.selectAll(interview);
        return PageInfo.of(list);
    }
}
